package com.test.nnooolwdeaer.view_wooden.info_input_wooden;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.bean_wooden.process_wooden.ProcessData_wooden;
import com.test.nnooolwdeaer.dialog_wooden.AddressSelectDialog_Niri_wooden;
import com.test.nnooolwdeaer.dialog_wooden.AddressSelectDialog_Viet_wooden;
import com.test.nnooolwdeaer.util_wooden.StringUtil_wooden;
import com.test.nnooolwdeaer.view_wooden.base_wooden.BaseInfoInputViewManager_wooden;


public class AddressPickViewManager_Viet_wooden extends BaseInfoInputViewManager_wooden {

    private TextView titleTv_wooden;
    private TextView inputTv_wooden;
    private View clickView_wooden;

    private AddressSelectDialog_Niri_wooden addressSelectDialog_wooden;

    private String state_wooden, city_wooden;

    public AddressPickViewManager_Viet_wooden(View view, ProcessData_wooden data){
        super(view,data,"");
    }

    @Override
    protected void init_wooden(){

        titleTv_wooden = mView_wooden.findViewById(R.id.view_address_pick_tv_title);
        inputTv_wooden = mView_wooden.findViewById(R.id.view_address_pick_tv_input);
        clickView_wooden = mView_wooden.findViewById(R.id.view_address_pick_layout_click);

        setTitle(mData_wooden.getTitle_wooden());
        inputTv_wooden.setHint(mData_wooden.getHint_wooden());

        clickView_wooden.setOnClickListener(v -> new AddressSelectDialog_Viet_wooden(mView_wooden.getContext(), inputTv_wooden, addressStrs -> {
            if (addressStrs.length<2) return;
            state_wooden = addressStrs[0];
            city_wooden = addressStrs[1];
        }).show());

    }


    @Override
    public boolean checkInput_wooden() {
        if (!mData_wooden.isMustInput_wooden()) return true;
        return (!TextUtils.isEmpty(state_wooden))&&(!TextUtils.isEmpty(city_wooden));
    }

    @Override
    public String getInput_wooden() {
        return StringUtil_wooden.getSafeString_wooden(inputTv_wooden.getText().toString());
    }

    public void setTitle(String title){
        if (TextUtils.isEmpty(title)) titleTv_wooden.setVisibility(GONE);
        else {
            titleTv_wooden.setVisibility(VISIBLE);
            titleTv_wooden.setText(title);
        }
    }

    public String getState_wooden() {
        return StringUtil_wooden.getSafeString_wooden(state_wooden);
    }

    public String getCity_wooden() {
        return StringUtil_wooden.getSafeString_wooden(city_wooden);
    }

}
